home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / progwin.zip / WINDOW2.ZIP / POPPAD1.C < prev    next >
Text File  |  1991-10-01  |  2KB  |  91 lines

  1.   /*-------------------------------------
  2.   POPPAD1.C -- Popup Editor Using Child Window Edit Box
  3.          (c) Charles Petzold, 1990
  4.   ---------------------------------------*/
  5.   #include <windows.h>
  6.  
  7.   long FAR PASCAL WndProc (HWND, WORD, WORD, LONG);
  8.   char szAppName[] = "PopPad1" ;
  9.  
  10.   int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  11.               LPSTR lpszCmdLine, int nCmdShow)
  12.        {
  13.  
  14.        HWND        hwnd;
  15.        MSG       msg;
  16.        WNDCLASS       wndclass;
  17.  
  18.        if (!hPrevInstance)
  19.         {
  20.         wndclass.style     = CS_HREDRAW | CS_VREDRAW;
  21.         wndclass.lpfnWndProc = WndProc;
  22.         wndclass.cbClsExtra     = 0;
  23.         wndclass.cbWndExtra     = 0;
  24.         wndclass.hInstance     = hInstance;
  25.         wndclass.hIcon     = LoadIcon (NULL,IDI_APPLICATION);
  26.         wndclass.hCursor     = LoadCursor (NULL, IDC_ARROW);
  27.         wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  28.         wndclass.lpszMenuName  = NULL;
  29.         wndclass.lpszClassName = szAppName;
  30.  
  31.         RegisterClass (&wndclass);
  32.         }
  33.  
  34.        hwnd = CreateWindow (szAppName, szAppName,
  35.                 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,
  36.                 GetSystemMetrics (SM_CXSCREEN) / 2,
  37.                 GetSystemMetrics (SM_CYSCREEN) / 2,
  38.                 NULL, NULL, hInstance, NULL) ;
  39.  
  40.        ShowWindow (hwnd, nCmdShow);
  41.        UpdateWindow (hwnd);
  42.  
  43.        while (GetMessage (&msg, NULL, 0, 0))
  44.         {
  45.         TranslateMessage (&msg);
  46.         DispatchMessage (&msg);
  47.         }
  48.        return msg.wParam;
  49.        }
  50.  
  51.  
  52.  
  53.   long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  54.  
  55.        {
  56.     static HWND hwndEdit ;
  57.        switch (message)
  58.         {
  59.         case WM_CREATE :
  60.          hwndEdit = CreateWindow ( " edit ", NULL,
  61.                 WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
  62.                 WS_BORDER | ES_LEFT | ES_MULTILINE|
  63.                 ES_AUTOHSCROLL | ES_AUTOVSCROLL,
  64.                 0,0,0,0,
  65.                 hwnd,1,
  66.                 ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
  67.          return 0 ;
  68.  
  69.         case WM_SETFOCUS :
  70.          SetFocus (hwndEdit) ;
  71.          return 0;
  72.  
  73.         case WM_SIZE :
  74.          MoveWindow (hwndEdit, 0, 0, LOWORD(lParam),
  75.                 HIWORD(lParam), TRUE) ;
  76.          return 0;
  77.  
  78.         case WM_COMMAND:
  79.         if(wParam == 1 && HIWORD( lParam ) == EN_ERRSPACE)
  80.             MessageBox (hwnd,"Edit control out of space.",
  81.                 szAppName,MB_OK | MB_ICONSTOP );
  82.         return 0;
  83.  
  84.         case WM_DESTROY:
  85.         PostQuitMessage(0);
  86.         return 0;
  87.          }
  88.        return DefWindowProc (hwnd,message,wParam,lParam);
  89.        }
  90.  
  91.